import { reqCategoryList, reqBannerList, reqFloorList } from "@/api"

//定义仓库的数据
const state = {
    categoryList: [],
    bannerList: [],
    floorList: []
}
// 唯一修改 state 的地方
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    BANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    FLOORLIST(state, floorList) {
        state.floorList = floorList
    }
}
// 处理派发action，处理异步语句，编辑逻辑
const actions = {
    // 获取数据的
    async categoryList({ commit }){
        let result = await reqCategoryList()
        if(result.code == 200) {
            commit("CATEGORYLIST",result.data)
        }
    },
    async getBannerList({ commit }){
        let result = await reqBannerList()
        if(result.code == 200) {
            commit("BANNERLIST",result.data)
        }
    },
    async getFloorList({ commit }){
        let result = await reqFloorList()
        // 提交
        if(result.code == 200) {
            commit("FLOORLIST",result.data)
        }
    },

}
// 计算属性
const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}